<?php
/**
 * Created by VsCode.
 * User: Zhanghaibin
 * Date: 2018/3/29
 * Time: 16:14
 */

namespace Admin\Controller;


use Think\Controller;
use Wechat\Model\ReplyLogic;
/**
 * 
 * 设置关键字回复
 * basic ->文字回复
 * images->图片回复
 * news  ->图文回复
 * music ->音乐回复
 * video ->视频回复
 * system-> 设置首次关注/默认回复关键字
 * 
 */
class MessageReplyController extends Controller
{

    const REPLY_MOUDLE    = 'basic';
    /**
     * 文字回复 列表
     */
    public function basic_index() {

        $this->display('MessageReply/basic_list');

    }

    /**
     * 文字回复 增加/修改
     */
    public function basic_edit() {

        $ruleId = I('rule_id');
        $basicReply = D('BasicReply');
        $replyRule  = D('ReplyRule');
        $conditions['moudle'] = self::REPLY_MOUDLE;
        $basicCondition['rule_id'] = $ruleId;
        $basicReplyResult = $basicReply->where($basicCondition)->find();
        //查找规则列表
        $conditions['rule_id'] = $ruleId;
        $ruleResult = $replyRule->where($conditions)
                                ->select();
        foreach ($ruleResult as $value) {
            //存在
            
            if (isset($rulesArray[$value['rule_id']])) {
                $tmpArray = array();
                //$ddd = $rulesArray[$value['rule_id']]['rule_keywords'];
                $tmpArray =explode(',',$rulesArray[$value['rule_id']]['rule_keywords']);// explode(',',$rulesArray[$value['rule_id']]['rule_keywords']);
                array_push($tmpArray,$value['rule_keywords']);
                $rulesArray[$value['rule_id']]['rule_keywords'] =implode(',',$tmpArray);
            } else {
                $data=array();
                $data['rule_name'] = $value['rule_name'];
                $data['rule_keywords'] = $value['rule_keywords'];
                $data['rule_status'] = $value['rule_status'];
                $rulesArray[$value['rule_id']] = $data;
            }
        }
        $basicReplyResult['rule'] = $rulesArray[ $ruleId];
       
        $this->assign("basic_info",$basicReplyResult);

        $this->display('MessageReply/basic_add');

    }

    /**
     * 图片回复 列表
     */
    public function images_index() {

        $this->display('MessageReply/images_list');

    }

    /**
     * 图片回复 增加/修改
     */
    public function images_edit() {

        $this->display('MessageReply/images_add');

    } 
    
    /**
     * 图文回复 列表
     */
    public function news_index() {

        $this->display('MessageReply/news_list');

    }

    /**
     * 图文回复 增加/修改
     */
    public function news_edit() {

        $this->display('MessageReply/news_add');

    } 
    
    /**
     * 音乐回复 列表
     */
    public function music_index() {

        $this->display('MessageReply/music_list');

    }

    /**
     * 音乐回复 增加/修改
     */
    public function music_edit() {

        $this->display('MessageReply/music_add');

    } 
    
    /**
     * 视频回复 列表
     */
    public function video_index() {

        $this->display('MessageReply/video_list');

    }

    /**
     * 视频回复 增加/修改
     */
    public function video_edit() {

        $this->display('MessageReply/video_add');

    } 
   
}   